<template>
  <div id="toolBar">
    <button @click="drawBillboard">绘制点</button>
    <button @click="drawLine">绘制线</button>
    <button @click="drawPolygon">绘制面</button>
    <button @click="clearOne">单个清除</button>
    <button @click="clearAll">全部清除</button>
  </div>
</template>

<script lang="ts" setup>
import { inject, onMounted } from 'vue'
import { Viewer } from 'cesium'
import { DrawPolt } from '@/draw/index'
const viewer = inject<Viewer>('Viewer')!
let draw: DrawPolt
let drawElement: HTMLElement | null = null
onMounted(() => {
  /* eslint no-new: */
  draw = new DrawPolt({
    viewer
  })
  drawElement = document.querySelector('.cesium-widget, .cesium-widget canvas')
  draw.setCanvas(drawElement)
})
const drawBillboard = () => {
  draw.create('drawpoint')
}
const drawLine = () => {
  draw.create('drawpolyline')
}
const drawPolygon = () => {
  draw.create('drawpolygon')
}
const clearOne = () => {
  draw.clearOne()
}
const clearAll = () => {
  draw.clearAll()
}
</script>
<style scoped>
#cesiumContainer {
  width: 100%;
  height: 100%;
}
#toolBar {
  position: absolute;
  left: 20px;
  top: 20px;
  z-index: 2;
  background: white;
  padding: 5px 5px;
}
</style>
